# -- coding:utf8 --
import commands
import datetime

def backup():
    # cmd_str = "mysqldump -uroot -p*****  smart_home > /tmp/smart_home.sql"
    #配置 /etc/mysql/my.cnf
    # [msyqldump]
    # host=localhost
    # user=数据库用户
    # password='数据库密码'
    data_today =  datetime.datetime.now().strftime("%Y-%m-%d")
    cmd_str = "mysqldump --defaults-extra-file=/etc/mysql/my.cnf smart_home > /root/sql_file/%s" % ('smart_home'+data_today+'.sql')
    print(cmd_str)
    (status, output) = commands.getstatusoutput(cmd_str)
    print(status)

if __name__ == '__main__':
    backup()
